﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Mock1Group6
{
    public partial class ViewDetails : System.Web.UI.Page
    {
       static int CurrentPage;
       //static string CardNo = "1111111111111111";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["1weekago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 7);
            }
            if (Session["1monthago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(),30);
            }
            if (Session["4monthago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(),120);
            }
            if (Session["6monthago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(),180);
            }
            if (Session["1yearago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(),365);
            }
            if (Session["2yearago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(),730);
            }
        }
        
        protected void ViewHistory(string CardNo,int maxDate)
        {
            PagedDataSource page = new PagedDataSource();
            page.DataSource = BusinessLogic.ViewHistory.View_History(CardNo, maxDate).DefaultView;
            page.AllowPaging = true;
            page.PageSize = 5;
            page.CurrentPageIndex = CurrentPage;
            Button3.Enabled = !page.IsFirstPage;
            Button6.Enabled = !page.IsLastPage;
            grv.DataSource = page;
            grv.DataBind();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            CurrentPage -= 1;
            if (Session["1weekago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 7);
            }
            if (Session["1monthago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 30);
            }
            if (Session["4monthago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 120);
            }
            if (Session["6monthago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 180);
            }
            if (Session["1yearago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 365);
            }
            if (Session["2yearago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 730);
            }
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            CurrentPage += 1;
            if (Session["1weekago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 7);
            }
            if (Session["1monthago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 30);
            }
            if (Session["4monthago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 120);
            }
            if (Session["6monthago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 180);
            }
            if (Session["1yearago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 365);
            }
            if (Session["2yearago"] != null)
            {
                ViewHistory(Session["CardNo"].ToString(), 730);
            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("FormMain.aspx");
        }
    }
}